export class GameScene extends Phaser.Scene {
    constructor() {
        super({ key: 'GameScene' });
        this.grid = [];
        this.tiles = [];
        this.GRID_SIZE = 8;
        this.TILE_SIZE = 40;
        this.COLORS = ['blue', 'purple', 'orange'];
    }

    preload() {
        // 加载资源
        this.load.image('tile_blue', 'assets/tile_blue.png');
        this.load.image('tile_purple', 'assets/tile_purple.png');
        this.load.image('tile_orange', 'assets/tile_orange.png');
        this.load.image('stone', 'assets/stone.png');
    }

    create() {
        // 创建游戏背景
        this.add.rectangle(0, 0, 375, 667, 0x2c3e50).setOrigin(0);
        
        // 初始化网格
        this.initGrid();
        
        // 创建石头区域
        this.createStones();
    }

    initGrid() {
        const startX = (375 - this.GRID_SIZE * this.TILE_SIZE) / 2;
        const startY = 667 - this.GRID_SIZE * this.TILE_SIZE - 100;

        for (let i = 0; i < this.GRID_SIZE; i++) {
            this.grid[i] = [];
            this.tiles[i] = [];
            for (let j = 0; j < this.GRID_SIZE; j++) {
                const colorIndex = Phaser.Math.Between(0, this.COLORS.length - 1);
                const color = this.COLORS[colorIndex];
                
                const tile = this.add.sprite(
                    startX + j * this.TILE_SIZE,
                    startY + i * this.TILE_SIZE,
                    `tile_${color}`
                ).setOrigin(0);

                tile.setInteractive();
                this.grid[i][j] = color;
                this.tiles[i][j] = tile;
            }
        }
    }

    createStones() {
        // 创建石头堆积区域
        // 这里需要使用物理引擎来实现石头的堆积效果
    }
}